package com.gwnet.shop.utils;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class UniqueStringGenerator {
    private static final Random random = new Random();

    public static String generateUniqueString(int maxLength) {
        StringBuilder sb = new StringBuilder();
        long now = System.currentTimeMillis();
        String timeStr = Long.toString(now, 36); // 将时间戳转换为36进制字符串
        sb.append(timeStr);

        // 如果时间戳转换后的字符串长度小于maxLength，则补充随机数
        while (sb.length() < maxLength) {
            int randomChar = random.nextInt(36); // 生成0-35之间的随机数
            sb.append(Integer.toString(randomChar, 36).toUpperCase());
        }

        // 如果生成的字符串超过maxLength，则截取
        return sb.substring(0, maxLength);
    }

    public static String generateUniqueString() {
        StringBuilder sb = new StringBuilder();
        long now = System.currentTimeMillis();
        String timeStr = Long.toString(now, 36); // 将时间戳转换为36进制字符串
        sb.append(timeStr);

        // 如果时间戳转换后的字符串长度小于maxLength，则补充随机数
        while (sb.length() < 20) {
            int randomChar = random.nextInt(36); // 生成0-35之间的随机数
            sb.append(Integer.toString(randomChar, 36).toUpperCase());
        }

        // 如果生成的字符串超过maxLength，则截取
        return sb.substring(0, 20);
    }

    public static void main(String[] args) {
        //System.out.println(generateUniqueString(20));Long
        Map<Long,Long> map = new HashMap<>();
        map.put(1L,2L);
        map.put(1L,5L);

       String json = JSON.toJSONString(map);
        System.out.println(json);

    }
}
